package com.jin.webvideo.videoCache.policy;

import com.jin.webvideo.videoCache.policy.condition.Condition;
import com.jin.webvideo.videoCache.policy.operation.Operation;
import com.jin.webvideo.videoCache.policy.operation.OperationFactory;

import java.util.Map;

public class MapCondition implements Condition<Map<String,String>> {
    private String opStr;
    public MapCondition(String opStr){
        this.opStr = opStr;
    }

    @Override
    public boolean compute(Map<String,String> s) {
        String[] op = opStr.split("\\.");
        if (op.length != 3){
            return false;
        }
        Operation operation = OperationFactory.newInstance().get(op[1]);
        return operation.compute(s.get(op[0]), op[2]);
    }
}
